#include <bits/stdc++.h>
using namespace std;
int main() {
  //   id         v                       end  cost
  // vector<pair<int, priority_queue<pair<int, int>>>>
  // push task
  // pop task    min time
  using pli = pair<long long, int>;
  using pq = priority_queue<pli, vector<pli>, greater<pli>>;
  int n, m;
  cin >> n >> m;
  vector<pair<long long, pq>> computes(n);
  for (auto &[v, _] : computes) cin >> v;
  while (m--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    auto &[v, q] = computes[b - 1];
    while (!q.empty() && q.top().first <= a) {
      v += q.top().second;
      q.pop();
    }
    if (d > v) {
      cout << -1 << endl;
      continue;
    }
    v -= d;
    q.emplace(a + c, d);
    cout << v << endl;
  }
}